/*
 * AddPersonView.java
 *
 * Created on Mar 29, 2010, 9:47:33 PM
 */
package assetl.desktop;

import assetl.system.AssetLControl;
import assetl.system.DataPacket;
import assetl.system.PersonPacket;
import assetl.system.Person;

/**
 * Allows the admin to add Persons to the model
 * 
 * @author Devin Doman
 */
public class AddPersonView
   extends AssetView
{
   /**
    * Constructor for the user interface
    *
    * @param pControl The controller for this view
    */
   public AddPersonView(AssetLControl pControl)
   {
      super(pControl);
      initComponents();
   }

   /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      mINumLbl = new javax.swing.JLabel();
      mFirstLbl = new javax.swing.JLabel();
      mMiddleLbl = new javax.swing.JLabel();
      mLastLbl = new javax.swing.JLabel();
      mEmailLbl = new javax.swing.JLabel();
      mPhoneLbl = new javax.swing.JLabel();
      mINumTxtFld = new javax.swing.JTextField();
      mFirstTxtFld = new javax.swing.JTextField();
      mMiddleTxtFld = new javax.swing.JTextField();
      mLastTxtFld = new javax.swing.JTextField();
      mEMailTxtFld = new javax.swing.JTextField();
      mPhoneTxtFld = new javax.swing.JTextField();
      mAddBtn = new javax.swing.JButton();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      mINumLbl.setText("I-number:");
      mINumLbl.setName("mINumLbl"); // NOI18N

      mFirstLbl.setText("First");
      mFirstLbl.setName("mFirstLbl"); // NOI18N

      mMiddleLbl.setText("MI");
      mMiddleLbl.setName("mMiddleLbl"); // NOI18N

      mLastLbl.setText("Last");
      mLastLbl.setName("mLastLbl"); // NOI18N

      mEmailLbl.setText("e-mail");
      mEmailLbl.setName("mEmailLbl"); // NOI18N

      mPhoneLbl.setText("Phone");
      mPhoneLbl.setName("mPhoneLbl"); // NOI18N

      mINumTxtFld.setName("mINumTxtFld"); // NOI18N

      mFirstTxtFld.setName("mFirstTxtFld"); // NOI18N

      mMiddleTxtFld.setName("mMiddleTxtFld"); // NOI18N

      mLastTxtFld.setName("mLastTxtFld"); // NOI18N

      mEMailTxtFld.setName("mEMailTxtFld"); // NOI18N

      mPhoneTxtFld.setName("mPhoneTxtFld"); // NOI18N

      mAddBtn.setText("Add Person");
      mAddBtn.setName("mAddBtn"); // NOI18N

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                  .addGap(36, 36, 36)
                  .addComponent(mINumLbl)
                  .addGap(18, 18, 18)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                     .addComponent(mINumTxtFld, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addGroup(layout.createSequentialGroup()
                              .addComponent(mFirstTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                              .addComponent(mMiddleTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                           .addGroup(layout.createSequentialGroup()
                              .addComponent(mFirstLbl)
                              .addGap(51, 51, 51)
                              .addComponent(mMiddleLbl)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(mLastTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                           .addComponent(mLastLbl)))))
               .addGroup(layout.createSequentialGroup()
                  .addGap(97, 97, 97)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(mEmailLbl)
                     .addComponent(mEMailTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(26, 26, 26)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(mPhoneLbl)
                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(mAddBtn)
                        .addComponent(mPhoneTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))))
            .addGap(105, 105, 105))
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addGap(49, 49, 49)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(mINumLbl)
               .addComponent(mINumTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(24, 24, 24)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(mFirstLbl)
               .addComponent(mMiddleLbl)
               .addComponent(mLastLbl))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(mFirstTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(mMiddleTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(mLastTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(mEmailLbl)
               .addComponent(mPhoneLbl))
            .addGap(27, 27, 27)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(mEMailTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(mPhoneTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addComponent(mAddBtn)
            .addGap(25, 25, 25))
      );

      pack();
   }// </editor-fold>//GEN-END:initComponents
   // Variables declaration - do not modify//GEN-BEGIN:variables
   /**
   * Button to add a person with
   */
   private javax.swing.JButton mAddBtn;
   /**
   * The text field for the email
   */
   private javax.swing.JTextField mEMailTxtFld;
   /**
   * Label for email
   */
   private javax.swing.JLabel mEmailLbl;
   /**
   * Label for the first name
   */
   private javax.swing.JLabel mFirstLbl;
   /**
   * The text field for the first name
   */
   private javax.swing.JTextField mFirstTxtFld;
   /**
   * Label for the I-number
   */
   private javax.swing.JLabel mINumLbl;
   /**
   * The text field for the I-number
   */
   private javax.swing.JTextField mINumTxtFld;
   /**
   * Label for the last name
   */
   private javax.swing.JLabel mLastLbl;
   /**
   * The text field for the last name
   */
   private javax.swing.JTextField mLastTxtFld;
   /**
   * Label for the middle initial
   */
   private javax.swing.JLabel mMiddleLbl;
   /**
   * The text field for the middle initial
   */
   private javax.swing.JTextField mMiddleTxtFld;
   /**
   * Label for phone number
   */
   private javax.swing.JLabel mPhoneLbl;
   /**
   * The text field for the phone number
   */
   private javax.swing.JTextField mPhoneTxtFld;
   // End of variables declaration//GEN-END:variables

   /**
    * Updates the views display of the model
    */
   public void updateData()
   {
   }

   /**
    * Grabs all pertainent data from the fields and sets them in
    * a DataPacket object. This DataPacket is then returned by the
    * method.
    *
    * @param pFunction The function that needs the DataPacket
    * @return The DataPacket that has been set
    */
   public DataPacket grabDataPacket(String pFunction)
   {
      PersonPacket packet = null;

      String id = mINumTxtFld.getText();
      String first = mFirstTxtFld.getText();
      String middle = mMiddleTxtFld.getText();
      String last = mLastTxtFld.getText();
      String email = mEMailTxtFld.getText();
      String phone = mPhoneTxtFld.getText();

      Person myPerson = new Person(id, first, middle, last, email, phone);
      packet = new PersonPacket(myPerson);

      return packet;
   }

   /**
    * Enables functionality passed in for this view.
    */
   public void enable(String pFunction)
   {
      //Enable a FunctionListener for the button
      enable(pFunction, mAddBtn, "Function");
   }

   /**
    * The entry point for this view
    */
   public void run()
   {
      enable("AddPerson");
   }
}
